package com.iversonx.example_1.controller.v2.impl;

import com.iversonx.example_1.controller.AwardReq;
import com.iversonx.example_1.controller.v2.PrizeService;
import com.iversonx.example_1.service.coupon.CouponResult;
import com.iversonx.example_1.service.coupon.CouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CouponPrizeService implements PrizeService {
    private final Logger logger = LoggerFactory.getLogger(CouponPrizeService.class);
    @Autowired
    private CouponService couponService;

    @Override
    public boolean support(Integer awardType) {
        return awardType == 1;
    }

    @Override
    public void sendCommodity(AwardReq req) throws Exception {
        logger.info("请求参数[优惠券] => {}", req);
        CouponResult couponResult = couponService.sendCoupon(req.getUId(), req.getAwardNumber(), req.getBizId());
        logger.info("测试结果[优惠券]：{}", couponResult);
        if (!"0000".equals(couponResult.getCode())) throw new RuntimeException(couponResult.getInfo());
    }
}
